package com.gaga.metadata.result;

import com.gaga.metadata.entity.database.DataBaseColumn;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.collections4.CollectionUtils;

import java.time.LocalDateTime;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * SelectResult
 *
 * @author liujia
 * @since 2021/7/19 23:31
 */
public class JdbcSelectResult extends AbstractResult implements IResult {
    @Getter
    @Setter
    private List<DataBaseColumn> columns;
    @Getter
    @Setter
    private List<LinkedHashMap<String, Object>> rowData;
    @Getter
    @Setter
    private Integer total;
    @Getter
    @Setter
    private Integer page;
    @Getter
    @Setter
    private Integer limit;
    /**
     * 执行器id
     */
    @Getter
    @Setter
    private String executeId;

    public JdbcSelectResult() {
    }

    public static JdbcSelectResult buildResult() {
        JdbcSelectResult result = new JdbcSelectResult();
        result.setStartTime(LocalDateTime.now());
        return result;
    }

    public String getCalcType() {
        String calcType = "";
        if (CollectionUtils.isNotEmpty(rowData)) {
            calcType = (String) rowData.get(0).get("calcType");
        }
        return calcType;
    }

//    public void setStatusList(List<Object> statusList) {
//        this.setColumns(STATUS_COLUMN);
//        List<LinkedHashMap<String, Object>> dataList = new ArrayList<>();
//        for (Object item : statusList) {
//            LinkedHashMap map = new LinkedHashMap<String, Object>();
//            map.put(STATUS, item);
//            dataList.add(map);
//        }
//        this.setRowData(dataList);
//        this.setTotal(statusList.size());
//    }
}
